package com.le.tester.leetcode;

import com.le.tester.leetcode.common.ListNode;

/**
 * createTime：2021/8/23 16:15
 * description：reverseList反转链表
 */
public class ReverseList {
    public ListNode reverseList(ListNode head) {

//        if (head == null || head.next == null) {
//            return head;
//        }
//        ListNode newHead = this.reverseList(head.next);
//        head.next.next = head;
//        //head.getNext().setNext(head);
//        //head.setNext(null);
//        head.next = null;
//        return newHead;

        ListNode newHead = null;
        ListNode curHead = head;

        while (curHead != null) {
            ListNode next = curHead.next;
            curHead.next = newHead;
            newHead = curHead;
            curHead = next;

        }
        return newHead;
    }
}
